package com.luozhili.io;

import com.luozhili.io.base.IoDemoBase;
import com.luozhili.io.entity.Student;

import java.io.*;

public class ObjectDemo extends IoDemoBase {

    public void output() {
        Student student = new Student(01, "蔡徐坤", "女"); //在类的声明中添加了 序列化Serializable

        try {
            ObjectOutputStream objout = new ObjectOutputStream(new FileOutputStream("stu.ser"));
            objout.writeObject(student);
            objout.close();

        } catch (IOException e) {
            e.printStackTrace();
        }


    }

    public void input() {
        ObjectInputStream inputStream = null;
        try {
            inputStream = new ObjectInputStream(new FileInputStream("stu.ser"));
            Student stu=(Student)inputStream.readObject();

            System.out.println(stu.toString());


        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
